$KCODE = 'u'
require 'find'
require 'svn/client.rb'

# 对html，xml文件加上注释
# 
# @author: jun tsai
# @version $Revision: 9 $
# @since 0.0.1
# 
# 



def fix_xml_head_comment dir
  Find.find(dir)  do |file|
  
    if file=~/\.xml$/ || file=~/\.html$/ 
        puts file
         tmp_file_name=file+'.tmp'
         tmp_file=File.open(tmp_file_name,'w')
         is_content=false
         File.open(file).each{|line|
          is_content =true if (line =~ /<[\w|!]/  && !(line =~ /<!--/))
          tmp_file << line if is_content
        }
         tmp_file.close
        File.rename(tmp_file_name,file)
      end
  end
  
  Find.find(dir)  do |file|
    if file=~/\.xml$/ || file=~/\.html$/ 
        puts file
         tmp_file_name=file+'.tmp'
         tmp_file=File.open(tmp_file_name,'w')
        ctx=Svn::Client::Context.new  
        ctx.log(file,1,"HEAD",1,true,nil){|changed_paths, rev, author, date, message|
        currentYear = 2007
        createdYear = date.year
        
       
        copyYears=createdYear.to_s+"-"+currentYear.to_s
        copyYears="2007" if currentYear == createdYear
        
        puts copyYears
  
            tmp_file << "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<!-- 
  Copyright #{copyYears} the original author or authors.
  
  Licensed under the Apache License, Version 2.0 (the \"License\");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
    http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an \"AS IS\" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->\n"
           
         }
         File.open(file).each{|line|
            tmp_file << line
          }
         tmp_file.close
        File.rename(tmp_file_name,file)
      end
  end
end

dir=File.dirname(__FILE__)+'/../src'
fix_xml_head_comment dir
dir = File.dirname(__FILE__)+'/../webapp'
fix_xml_head_comment dir